package com.gitee.faster.webdav.kernel.protocol.filter;

import com.gitee.faster.webdav.common.structure.StringValue;
import com.gitee.faster.webdav.kernel.protocol.HttpExchange;
import lombok.extern.slf4j.Slf4j;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author hongda.li
 */
@Slf4j
public class HttpFilterLogger implements HttpFilter {

    @Override
    public int order() {
        return Integer.MIN_VALUE;
    }

    @Override
    public boolean doNext(HttpExchange httpExchange) {
        log.debug("Path   : {}", httpExchange.getPath());
        log.debug("Method : {}", httpExchange.getRequestMethod());

        Map<String, String> headerMap = new LinkedHashMap<>();
        StringValue headerValue = httpExchange.getHeaderValue();
        httpExchange.getHeaderNames().forEach(name -> headerMap.put(name, headerValue.getStr(name)));
        log.debug("Header : {}", headerMap);

        return true;
    }
}
